{extend name='common/_container'} {block name="content"}
<div class="row">
	<div class="col-sm-12">
		<div class="ibox float-e-margins">
			<div class="ibox-content">
				<div class="row row-lg">
					<div class="col-sm-12">
						<div class="row" id="searchGroup">
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">昵称</button>
									</div>
									<input type="text" autocomplete="off" class="form-control" id="nickname" name="nickname"  placeholder="昵称" />



								</div>


							</div>
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">手机号码</button>
									</div>
									<input type="text" autocomplete="off" class="form-control" id="phone" name="phone"  placeholder="手机号码" />

								</div>


							</div>
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">红娘等级</button>
									</div>
									<select name="level_id" id="level_id" class="form-control">
										<option value="">选择红娘等级</option>
										{foreach $level_rows as $key=>$vo }
										<option value="{$vo['id']}">{$vo['name']}</option>
										{/foreach}
									</select>
								</div>
							</div>


<!--							<div class="col-sm-2">-->
<!--								<div class="input-group">-->
<!--									<div class="input-group-btn">-->
<!--										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">市区</button>-->
<!--									</div>-->
<!--									<input type="text" autocomplete="off" class="form-control" id="city" placeholder="市区" />-->
<!--								</div>-->
<!--							</div>-->

							<div class="col-sm-3">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">创建时间范围</button>
									</div>
									<input type="text" autocomplete="off" placeholder="时间范围" class="form-control" id="createtime">
								</div>
							</div>



							<!--状态-->
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">状态</button>
									</div>
									<select class="form-control" id="status">
										<option value="">请选择</option>
										<option value="1">通过</option>
										<option value="0">待审核</option>
										<option value="2">拒绝</option>
									</select>
								</div>
							</div>
							<!-- search end -->
							<div class="col-sm-1">
								<button type="button" class="btn btn-success " onclick="CodeGoods.search()" id="">
									<i class="fa fa-search"></i>&nbsp;搜索
								</button>
							</div>
						</div>
						<div class="btn-group-sm" id="CodeGoodsTableToolbar" role="group">
						</div>
						<!--lwx 添加红娘-->
						{if condition="in_array('backend/ZhMatchmaker/add',session('backend.nodes')) || session('backend.role_id') eq 1"}
						<button type="button" id="add" class="btn btn-primary button-margin" onclick="CodeGoods.add()">
							<i class="fa fa-plus"></i>&nbsp;添加
						</button>
						{/if}
						{if condition="in_array('backend/ZhMatchmaker/update',session('backend.nodes')) || session('backend.role_id') eq 1"}
						<button type="button" id="update" class="btn btn-success button-margin" onclick="CodeGoods.update()">
							<i class="fa fa-pencil"></i>&nbsp;修改
						</button>
						{/if}
						{if condition="in_array('backend/ZhMatchmaker/delete',session('backend.nodes')) || session('backend.role_id') eq 1"}
						<button type="button" id="delete" class="btn btn-danger button-margin" onclick="CodeGoods.delete()">
							<i class="fa fa-trash"></i>&nbsp;删除
						</button>
						{/if}
						{if condition="in_array('backend/ZhMatchmaker/import',session('backend.nodes')) || session('backend.role_id') eq 1"}
						<button type="button" id="import" class="btn btn-primary button-margin" >
							导入
						</button>
						{/if}
						{if condition="in_array('backend/ZhMatchmaker/import',session('backend.nodes')) || session('backend.role_id') eq 1"}
						<a type="button" class="btn btn-primary button-margin" target="_blank" href="__PUBLIC__/static/excel/红娘导入模板.xls">
							 下载导入模板
						</a>
						{/if}
<a type="button" class="btn btn-primary button-margin" target="_blank" href="export">
							 导出
						</a>
						<table id="CodeGoodsTable" data-mobile-responsive="true" data-click-to-select="true">
							<thead><tr><th data-field="selectItem" data-checkbox="true"></th></tr></thead>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script src="__PUBLIC__/static/js/plugins/layui/layui.js" charset="utf-8"></script>
<script>

	var CodeGoods = {id: "CodeGoodsTable",seItem: null,table: null,layerIndex: -1};


	layui.use(['form', 'upload','layer'], function () {
		var upload = layui.upload;
		var layer = layui.layer

		var uploadInst = upload.render({
			elem: '#import' //绑定元素
			,accept: 'file'
			,exts:'xls'
			,url: Feng.ctxPath + "/ZhMatchmaker/import" //上传接口
			,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
				layer.load(); //上传loading
			}
			,done: function(data){
				layer.closeAll('loading'); //关闭loading
				//上传完毕回调
				if ('00' === data.status) {
					Feng.success(data.msg, 1000);
					CodeGoods.table.refresh();
				} else {
					Feng.error(data.msg + "！", 1000);
				}
			}
			,error: function(){
				layer.closeAll('loading'); //关闭loading
				//请求异常回调
			}
		});
	});

	CodeGoods.initColumn = function () {
 		return [
 			{field: 'selectItem', checkbox: true},
			{title: '操作', field: '', visible: true, width:'155px',align: 'center', valign: 'middle',formatter: 'CodeGoods.buttonFormatter'},
 			{title: '编号', field: 'matchmaker_id', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '红娘昵称', field: 'name', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '红娘等级', field: 'level_name', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '性别', field: 'sex', visible: true, align: 'center', valign: 'middle',sortable: true, formatter:'CodeGoods.sexFormatter'},
			{title: '年龄', field: 'age', visible: true, align: 'center', valign: 'middle',sortable: true},
			{title: '手机号码', field: 'phone', visible: true, align: 'center', valign: 'middle',sortable: true},
			{title: '上级推荐人', field: 'top_matchmaker_name', visible: true, align: 'center', valign: 'middle',sortable: true},
			{title: '真实姓名', field: 'real_name', visible: true, align: 'center', valign: 'middle',sortable: true},
			{title: '头像', field: 'head_portrait', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.avatarFormatter},
			{title: '状态', field: 'status', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.statusFormatter},
			{title: '首页显示', field: 'show_home', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.showHomeFormatter},
			{title: '邀请佳人数', field: 'child_num', visible: true, align: 'center', valign: 'middle',sortable: true},
			{title: '下级佳人数', field: 'lower_matchmaker_num', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '邀请红娘数', field: 'matchmaker_num', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '有效资料数', field: 'authentication_num', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '可提现余额', field: 'balance', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '从业经验', field: 'work_years', visible: true, align: 'center', valign: 'middle',sortable: true},
			{title: '省市区', field: 'city', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.cityFormatter},
			//{title: '地址', field: 'address', visible: true, align: 'center', valign: 'middle',sortable: true},

			{title: '到期时间', field: 'expiretime', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.createtimeFormatter},
			{title: '创建时间', field: 'createtime', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.createtimeFormatter},
 		];
 	};

	CodeGoods.avatarFormatter = function(value,row,index) {
		if(value){
			return "<a href=\"javascript:void(0)\" onclick=\"openImg('"+value+"')\"><img height='30' src="+value+"></a>";
		}
	}

	CodeGoods.sexFormatter = function(value,row,index) {
		if(value !== null){
			var value = value.toString();
			switch(value){
				case '1':
					return '<span class="label label-success">男</span>';
				break;
				case '2':
					return '<span class="label label-warning">女</span>';
				break;
			}
		}
	}

	CodeGoods.cityFormatter = function(value,row,index) {
		if (row.county){
			return row.province+""+row.city+""+row.county
		}

		if (row.city){
			return row.province+""+row.city
		}

		if (row.province){
			return row.province
		}
	}


	//lwx 添加红娘
	CodeGoods.add = function (value) {
		var url = location.search;
		var index = layer.open({type: 2,title: '添加',area: ['800px', '500px'],fix: false, maxmin: true,content: Feng.ctxPath + '/ZhMatchmaker/add'+url});
		this.layerIndex = index;
		if(!IsPC()){layer.full(index)}
	}
	CodeGoods.buttonFormatter = function(value,row,index) {
		if(row.matchmaker_id){
			var str= '';
			{if condition="in_array('backend/ZhMatchmaker/update',session('backend.nodes')) || session('backend.role_id') eq 1"}
			str += '<button type="button" class="btn btn-success btn-xs" title="修改"  onclick="CodeGoods.update('+row.matchmaker_id+')"><i class="fa fa-pencil"></i>&nbsp;修改</button>&nbsp;';
			{/if}
			{if condition="in_array('backend/ZhMatchmaker/delete',session('backend.nodes')) || session('backend.role_id') eq 1"}
			str += '<button type="button" class="btn btn-danger btn-xs" title="删除"  onclick="CodeGoods.delete('+row.matchmaker_id+')"><i class="fa fa-trash"></i>&nbsp;删除</button>&nbsp;';
			{/if}
			{if condition="in_array('backend/ZhMatchmaker/view',session('backend.nodes')) || session('backend.role_id') eq 1"}
			str += '<button type="button" class="btn btn-info btn-xs" title="查看详情"  onclick="CodeGoods.view('+row.matchmaker_id+')"><i class="fa fa-eye"></i>&nbsp;查看</button>&nbsp;';
			{/if}

				str += '<button type="button" class="btn btn-info btn-xs" title="查看下级"  onclick="CodeGoods.childList('+row.matchmaker_id+')"><i class="fa fa-eye"></i>&nbsp;查看下级</button>&nbsp;';


				return str;
		}
	}

	CodeGoods.is_personalFormatter = function(value,row,index) {
		if(value !== null){
			var value = value.toString();
			switch(value){
				case '1':
					return '<span class="label label-success">个人</span>';
				break;
				case '0':
					return '<span class="label label-warning">机构</span>';
				break;
			}
		}
	}

	CodeGoods.createtimeFormatter = function(value,row,index) {
		if(value){
			return formatDateTime(value,'Y-m-d H:i:s');
		}
	}

	CodeGoods.showHomeFormatter = function(value,row,index) {
		if(value !== null){
			var value = value.toString();
			switch(value){
				case '1':
					return '<span class="label label-success">显示</span>';
					break;
				case '0':
					return '<span class="label label-warning">不显示</span>';
					break;
			}
		}
	}

	CodeGoods.statusFormatter = function(value,row,index) {
		if(value !== null){
			var value = value.toString();
			switch(value){
				case '1':
					return '<span class="label label-success">通过</span>';
				break;
				case '0':
					return '<span class="label label-warning">待审核</span>';
				break;
				case '2':
					return '<span class="label label-info">拒绝</span>';
				break;
			}
		}
	}

	CodeGoods.formParams = function() {
		var queryData = {};
		queryData['offset'] = 0;
		queryData['nickname'] = $("#nickname").val();
		queryData['phone'] = $("#phone").val();
		queryData['city'] = $("#city").val();
		queryData['is_personal'] = $("#is_personal").val();
		queryData['organization_name'] = $("#organization_name").val();
		queryData['level_id'] = $("#level_id").val();
		queryData['createtime_start'] = $("#createtime").val().split(" - ")[0];
		queryData['createtime_end'] = $("#createtime").val().split(" - ")[1];
		queryData['status'] = $("#status").val();
		return queryData;
	}

	CodeGoods.check = function () {
		var selected = $('#' + this.id).bootstrapTable('getSelections');
		if(selected.length == 0){
			Feng.info("请先选中表格中的某一记录！");
			return false;
		}else{
			CodeGoods.seItem = selected;
			return true;
		}
	};

	CodeGoods.update = function (value) {
		if(value){
			var index = layer.open({type: 2,title: '修改',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/ZhMatchmaker/update?matchmaker_id='+value});
			if(!IsPC()){layer.full(index)}
		}else{
			if (this.check()) {
				var idx = '';
				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.matchmaker_id;
				});
				idx = idx.substr(1);
				if(idx.indexOf(",") !== -1){
					Feng.info("请选择单条数据！");
					return false;
				}
				var index = layer.open({type: 2,title: '修改',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/ZhMatchmaker/update?matchmaker_id='+idx});
				this.layerIndex = index;
				if(!IsPC()){layer.full(index)}
			}
		}
	}


	CodeGoods.delete = function (value) {
		if(value){
			Feng.confirm("是否删除选中项？", function () {
				var ajax = new $ax(Feng.ctxPath + "/ZhMatchmaker/delete", function (data) {
					if ('00' === data.status) {
						Feng.success(data.msg);
						CodeGoods.table.refresh();
					} else {
						Feng.error(data.msg);
					}
				});
				ajax.set('matchmaker_id', value);
				ajax.start();
			});
		}else{
			if (this.check()) {
				var idx = '';
				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.matchmaker_id;
				});
				idx = idx.substr(1);
				Feng.confirm("是否删除选中项？", function () {
					var ajax = new $ax(Feng.ctxPath + "/ZhMatchmaker/delete", function (data) {
						if ('00' === data.status) {
							Feng.success(data.msg,1000);
							CodeGoods.table.refresh();
						} else {
							Feng.error(data.msg,1000);
						}
					});
					ajax.set('matchmaker_id', idx);
					ajax.start();
				});
			}
		}
	}


	CodeGoods.view = function (value) {
		if(value){
			var index = layer.open({type: 2,title: '查看详情',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/ZhMatchmaker/view?matchmaker_id='+value});
			if(!IsPC()){layer.full(index)}
		}else{
			if (this.check()) {
				var idx = '';
				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.matchmaker_id;
				});
				idx = idx.substr(1);
				if(idx.indexOf(",") !== -1){
					Feng.info("请选择单条数据！");
					return false;
				}
				var index = layer.open({type: 2,title: '查看详情',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/ZhMatchmaker/view?matchmaker_id='+idx});
				this.layerIndex = index;
				if(!IsPC()){layer.full(index)}
			}
		}
	}
	//lwx 下级用户数
	CodeGoods.childList = function (value) {
		if(value){
			var index = layer.open({type: 2,title: '查看下级用户',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/ZhMatchmaker/childList?matchmaker_id='+value});
			if(!IsPC()){layer.full(index)}
		}else{
			if (this.check()) {
				var idx = '';
				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.matchmaker_id;
				});
				idx = idx.substr(1);
				if(idx.indexOf(",") !== -1){
					Feng.info("请选择单条数据！");
					return false;
				}
				var index = layer.open({type: 2,title: '查看下级用户',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/ZhMatchmaker/childList?matchmaker_id='+idx});
				this.layerIndex = index;
				if(!IsPC()){layer.full(index)}
			}
		}
	}

	CodeGoods.search = function() {
		CodeGoods.table.refresh({query : CodeGoods.formParams()});
	};

	$(function() {
		var defaultColunms = CodeGoods.initColumn();
		var url = location.search;
		var table = new BSTable(CodeGoods.id, Feng.ctxPath+"/ZhMatchmaker/index"+url,defaultColunms,20);
		table.setPaginationType("server");
		table.setQueryParams(CodeGoods.formParams());
		CodeGoods.table = table.init();
	});
	laydate.render({elem: '#createtime',type: 'datetime',range:true,
		ready: function(date){
			$(".layui-laydate-footer [lay-type='datetime'].laydate-btns-time").click();
			$(".laydate-main-list-1 .layui-laydate-content li ol li:last-child").click();
			$(".layui-laydate-footer [lay-type='date'].laydate-btns-time").click();
		}
	});
</script>
{/block}